package liste;

public class List
{
  private Node first;

  public List(int wert)
  {
    first = new Node(wert);
  }
  
  public int exchange(Node newNode)
  {
    Node tempNode = first;
    while(tempNode.next != null)
      tempNode = tempNode.next;
    tempNode.next = newNode;
    int re = first.value;
    first = first.next;
    return re;
  }
  
  public void addFirst(int wert)
  {
    Node newFirst = new Node(wert);
    newFirst.next = first;
    first = newFirst;
  }
  
  public int get(int pos)
  {
    Node n = first;
    
    for(int i = 0; i<pos; i++)
      if(n.next != null)
        n = n.next;
      else
        throw new RuntimeException();
    return n.value;
  }
  
  public String toString()
  {
    Node n = first;
    String output = first.value+"\n";
    while(n.next != null)
    {
      output += n.next.value+"\n";
      n = n.next;
    }
    return output;
  }
}

